home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / php / go-pear.php < prev    next >
Encoding:
PHP Script  |  2003-11-03  |  68.4 KB  |  2,318 lines

  1. <?php //; echo; echo "YOU NEED TO RUN THIS SCRIPT WITH PHP NOW!"; echo; echo "Try this: lynx -source http://pear.php.net/go-pear | php -q"; echo; exit # -*- PHP -*-
  2. # +----------------------------------------------------------------------+
  3. # | PHP Version 4                                                        |
  4. # +----------------------------------------------------------------------+
  5. # | Copyright (c) 1997-2002 The PHP Group                                |
  6. # +----------------------------------------------------------------------+
  7. # | This source file is subject to version 2.02 of the PHP license,      |
  8. # | that is bundled with this package in the file LICENSE, and is        |
  9. # | available at through the world-wide-web at                           |
  10. # | http://www.php.net/license/2_02.txt.                                 |
  11. # | If you did not receive a copy of the PHP license and are unable to   |
  12. # | obtain it through the world-wide-web, please send a note to          |
  13. # | license@php.net so we can mail you a copy immediately.               |
  14. # +----------------------------------------------------------------------+
  15. # | Authors: Tomas V.V.Cox <cox@idecnet.com>                             |
  16. # |          Stig Sµther Bakken <stig@php.net>                           |
  17. # |             Christian Dickmann <dickmann@php.net>                         |
  18. # |             Pierre-Alain Joye <pajoye@pearfr.org>                         |
  19. # +----------------------------------------------------------------------+
  20. # $Id: go-pear,v 1.52 2003/09/25 07:01:01 pajoye Exp $
  21. #
  22. # Automatically download all the files needed to run the "pear" command
  23. # (the PEAR package installer).  Requires PHP 4.1.0 or newer.
  24. #
  25. # Installation: Linux
  26. #
  27. # This script can either be directly launched or passed via lynx like this.
  28. #
  29. #  $ lynx -source http://pear.php.net/go-pear | php
  30. #
  31. # The above assumes your php binary is named php and that it's
  32. # executable through your PATH:
  33. #
  34. # Installation: Windows
  35. #
  36. # On Windows, go-pear uses stdin for user input, so you must download
  37. # go-pear first and then run it:
  38. #
  39. # Note: In PHP 4.2.0-4.2.3, the PHP CLI binary is named php-cli.exe while since
  40. # PHP 4.3.0, it's simply named php.exe in the cli/ folder of your PHP directory.
  41. # The CGI is also named php.exe but it sits directly in your PHP directory.
  42. #
  43. #  > cli/php -r "readfile('http://pear.php.net/go-pear');" > go-pear
  44. #  > cli/php go-pear
  45. #
  46. # Installation: Notes
  47. #
  48. # - If using the CGI version of PHP, append the -q option to suppress
  49. #   headers in the output.
  50. # - Once the go-pear script is initiated, you will see instructions on
  51. #   how to continue installing PEAR.  The first thing you should see is:
  52. #
  53. #   Welcome to go-pear!
  54. #
  55. # Installation: Web browser
  56. #
  57. # You can now use go-pear via a webbrowser, thanks to Christian Dickmann. It is
  58. # still beta codes, but feel free to test it:
  59. # 1.: Download the go-pear script by using the "Save target as ..." function
  60. # of your browser here.
  61. #
  62. # 2.: Place the go-pear file somewhere under the document root of your webserver.
  63. # The easiest way is to create a new directory for pear and to put the file in there.
  64. # Be sure your web server is setup to recognize PHP, and that you use an appropriate 
  65. # extension.  For example, you might name this file gopear.php
  66. #
  67. # 3.: Access go-pear through your webserver and follow the instructions. Please
  68. # make sure that PHP has write access to the dir you want to install PEAR into.
  69. # For example: http://localhost/pear/gopear.php
  70. #
  71. # 4.: After running go-pear you get a link to the Web Frontend of the PEAR installer.
  72. # I suggest bookmarking this link.
  73. #
  74. # 5.: Protect the Web Frontend directory and the go-pear script with a password.
  75. # Use .htaccess on Apache webservers for example.
  76. #
  77. #
  78. $sapi_name = php_sapi_name();
  79. set_time_limit(0);
  80. @ob_end_flush();
  81. ob_implicit_flush(true);
  82. define('WEBINSTALLER', (php_sapi_name() != 'cli' && !( substr(php_sapi_name(),0,3)=='cgi' && !isset($_SERVER['GATEWAY_INTERFACE']))));
  83.  
  84. ini_set('track_errors', true);
  85. ini_set('html_errors', WEBINSTALLER);
  86. ini_set('magic_quotes_runtime', false);
  87. error_reporting( E_ALL & ~E_NOTICE);
  88. define('WINDOWS', (substr(PHP_OS, 0, 3) == 'WIN'));
  89. define('GO_PEAR_VER', '0.2.2');
  90.  
  91. define('WIN32GUI', !WEBINSTALLER && WINDOWS && php_sapi_name()== 'cli' && which('cscript'));
  92.  
  93. /**
  94.  * See bug #23069
  95.  */
  96.  
  97. if ( WEBINSTALLER && WINDOWS ) {
  98.     $php_sapi_name = win32DetectPHPSAPI();
  99.     if($php_sapi_name=='cgi'){
  100.     $msg = nl2br("
  101. Sorry! The PEAR installer actually does not work on Windows platform using CGI and Apache.
  102. Please install the module SAPI (see http://www.php.net/manual/en/install.apache.php for the
  103. instructions) or use the CLI (cli\php.exe) in the console.
  104. ");
  105.         displayHTML('error', $msg);
  106.     }
  107. }
  108.  
  109. if (WEBINSTALLER && isset($_GET['action']) && $_GET['action'] == 'img' && isset($_GET['img'])) {
  110.     switch ($_GET['img'])
  111.     {
  112.         case 'note':
  113.         case 'pearlogo':
  114.         case 'smallpear':
  115.             showImage($_GET['img']);
  116.             exit;
  117.         default:
  118.             exit;
  119.     };
  120. }
  121.  
  122. // Check if PHP version is sufficient
  123. if (!function_exists("version_compare")) {
  124.     die("Sorry!  Your PHP version is too old.  PEAR and this script requires at
  125. least PHP 4.1.0 for stable operation.
  126.  
  127. It may be that you have a newer version of PHP installed in your web
  128. server, but an older version installed as the 'php' command.  In this
  129. case, you need to rebuilt PHP from source.
  130.  
  131. If your source is 4.1.x, you need to run 'configure' without any SAPI
  132. options such as --with-apache.  After rebuilding you will find the
  133. 'php' binary in the top-level directory.
  134.  
  135. If your source is 4.2.x, you need to run 'configure' with the
  136. --enable-cli option, rebuild and copy sapi/cli/php somewhere.
  137.  
  138. If your source is 4.3.x or newer, just make sure you don't run
  139. 'configure' with --disable-cli, rebuilt and copy sapi/cli/php.
  140.  
  141. Please upgrade PHP to a newer version, and try again.  See you then.
  142.  
  143. ");
  144. }
  145.  
  146. $installer_packages = array(
  147.     'PEAR',
  148.     'Archive_Tar',
  149.     'Console_Getopt',
  150.     'XML_RPC'
  151.     );
  152. if (WEBINSTALLER) {
  153.     $installer_packages[] = 'Pager';
  154.     $installer_packages[] = 'HTML_Template_IT';
  155.     $installer_packages[] = 'Net_UserAgent_Detect';
  156.     $installer_packages[] = 'PEAR_Frontend_Web';
  157. }
  158. $pfc_packages = array(
  159.     'DB',
  160.     'Net_Socket',
  161.     'Net_SMTP',
  162.     'Mail',
  163.     'XML_Parser',
  164.     'phpUnit'
  165.     );
  166. $config_desc = array(
  167.     'prefix' => 'Installation prefix',
  168.     'bin_dir' => 'Binaries directory',
  169.     'php_dir' => 'PHP code directory ($php_dir)',
  170.     'doc_dir' => 'Documentation base directory',
  171.     'data_dir' => 'Data base directory',
  172.     'test_dir' => 'Tests base directory',
  173. );
  174. if(!WEBINSTALLER && WINDOWS){
  175.     $config_desc['php_bin'] = 'php.exe path';
  176. }
  177. if (WEBINSTALLER) {
  178.     $config_desc['cache_dir'] = 'PEAR Installer cache directory';
  179.     $config_desc['cache_ttl'] = 'Cache TimeToLive';
  180.     $config_desc['webfrontend_file'] = 'Filename of WebFrontend';
  181.     $config_desc['php_bin'] = "php.exe path, optional (CLI command tools)";
  182. }
  183.  
  184. if (my_env('HTTP_PROXY')) {
  185.     $http_proxy = my_env('HTTP_PROXY');
  186. } elseif (my_env('http_proxy')) {
  187.     $http_proxy = my_env('http_proxy');
  188. } else {
  189.     $http_proxy = '';
  190. }
  191.  
  192. register_shutdown_function('bail');
  193.  
  194. detect_install_dirs();
  195.  
  196. if (WEBINSTALLER) {
  197.     @session_start();
  198.  
  199.     /*
  200.         See bug #23069
  201.     */
  202.     if ( WINDOWS ) {
  203.         $php_sapi_name = win32DetectPHPSAPI();
  204.         if($php_sapi_name=='cgi'){
  205.             $msg = "
  206.     Sorry! The PEAR installer actually does not work on Windows platform using CGI and Apache.
  207.     Please install the module SAPI (see http://www.php.net/manual/en/install.apache.php for the
  208.     instructions) or use the CLI (cli\php.exe) in the console.
  209.     ";
  210.             displayHTML('error', $msg);
  211.             exit();
  212.         }
  213.     }
  214.  
  215.     if (!isset($_SESSION['go-pear']) || isset($_GET['restart'])) {
  216.         $sep = WINDOWS ? "\\" : '/';
  217.         $_SESSION['go-pear'] = array(
  218.             'http_proxy' => $http_proxy,
  219.             'config' => array(
  220.                 'prefix' => dirname(__FILE__),
  221.                 'bin_dir' => $bin_dir,
  222.                 'php_bin' => $php_bin,
  223.                 'php_dir' => '$prefix'.$sep.'PEAR',
  224.                 'doc_dir' => $doc_dir,
  225.                 'data_dir' => $data_dir,
  226.                 'test_dir' => $test_dir,
  227.                 'cache_dir' => '$php_dir'.$sep.'cache',
  228.                 'cache_ttl' => 300,
  229.                 'webfrontend_file' => '$prefix'.$sep.'index.php',
  230.                 ),
  231.             'install_pfc' => true,
  232.             'DHTML' => true,
  233.             );
  234.     }
  235.     if (!isset($_GET['step'])) {
  236.         $_GET['step'] = 'Welcome';
  237.         /* clean up old sessions datas */
  238.         session_destroy();
  239.     }
  240.     if ($_GET['step'] == 'install') {
  241.         $_SESSION['go-pear']['http_proxy'] = strip_magic_quotes($_POST['proxy']['host']).':'.strip_magic_quotes($_POST['proxy']['port']);
  242.         if ($_SESSION['go-pear']['http_proxy'] == ':') {
  243.             $_SESSION['go-pear']['http_proxy'] = '';
  244.         };
  245.  
  246.         $www_errors = array();
  247.         foreach($_POST['config'] as $key => $value) {
  248.             $_POST['config'][$key] = strip_magic_quotes($value);
  249.             if($key!='cache_ttl'){
  250.                 if( ereg(' ', $_POST['config'][$key]) ) {
  251.                     $www_errors[$key] = 'Spaces are not allowed in pathes. Please choose another path.';
  252.                 } elseif ( empty($_POST['config'][$key]) ) {
  253.                     $www_errors[$key] = 'Please fill this path, you can use $prefix, $php_dir or a full path.';
  254.                 }
  255.             }
  256.         }
  257.  
  258.         if( sizeof($www_errors)>0){
  259.             $_GET['step'] = 'config';
  260.         }
  261.  
  262.         $_SESSION['go-pear']['config'] = $_POST['config'];
  263.         $_SESSION['go-pear']['install_pfc'] = (isset($_POST['install_pfc']) && $_POST['install_pfc'] == 'on');
  264.         $_SESSION['go-pear']['DHTML'] = !($_POST['BCmode'] == "on");
  265.     }
  266.  
  267.     $http_proxy = $_SESSION['go-pear']['http_proxy'];
  268.     foreach($_SESSION['go-pear']['config'] as $var => $value) {
  269.         $$var = $value;
  270.     }
  271.     $install_pfc = $_SESSION['go-pear']['install_pfc'];
  272. }
  273.  
  274. if (!WEBINSTALLER) {
  275.     $tty = WINDOWS ? @fopen('\con', 'r') : @fopen('/dev/tty', 'r');
  276.  
  277.     if (!$tty) {
  278.         $tty = fopen('php://stdin', 'r');
  279.     }
  280.  
  281.     print "Welcome to go-pear!
  282.  
  283. Go-pear will install the 'pear' command and all the files needed by
  284. it.  This command is your tool for PEAR installation and maintenance.
  285.  
  286. Go-pear also lets you download and install the PEAR packages bundled
  287. with PHP: " . implode(', ', $pfc_packages) . ".
  288.  
  289. If you wish to abort, press Control-C now, or press Enter to continue: ";
  290.  
  291.     fgets($tty, 1024);
  292.  
  293.     print "\n";
  294.  
  295.         print "HTTP proxy (http://user:password@proxy.myhost.com:port), or Enter for none:";
  296.  
  297.     if (!empty($http_proxy)) {
  298.         print " [$http_proxy]";
  299.     }
  300.     print ": ";
  301.     $tmp = trim(fgets($tty, 1024));
  302.     if (!empty($tmp)) {
  303.         $http_proxy = $tmp;
  304.     }
  305. }
  306.  
  307. $origpwd = getcwd();
  308.  
  309. $config_vars = array_keys($config_desc);
  310.  
  311. // make indices run from 1...
  312. array_unshift($config_vars, "");
  313. unset($config_vars[0]);
  314. reset($config_vars);
  315. $desclen = max(array_map('strlen', $config_desc));
  316. $descfmt = "%-{$desclen}s";
  317. $first = key($config_vars);
  318. end($config_vars);
  319. $last = key($config_vars);
  320.  
  321. if (WEBINSTALLER) {
  322.     if ( isset($www_errors) && sizeof($www_errors) ) {
  323.         displayHTML('config');
  324.         exit();
  325.     } else {
  326.         if (isset($_SESSION['go-pear']['DHTML']) && $_SESSION['go-pear']['DHTML'] == true && $_GET['step'] == 'install') {
  327.             $_GET['step'] = 'preinstall';
  328.         }
  329.         if ($_GET['step'] != 'install' && $_GET['step'] != 'install-progress') {
  330.             displayHTML($_GET['step']);
  331.             exit;
  332.         }
  333.         if ($_GET['step'] == 'install-progress') {
  334.             displayHTMLHeader();
  335.             echo "Starting installation ...<br/>";
  336.         }
  337.         ob_start();
  338.     }
  339. }
  340.  
  341. $progress = 0;
  342.  
  343. /*
  344.  * Checks PHP SAPI version under windows/CLI
  345.  */
  346. if( WINDOWS && !WEBINSTALLER && $php_bin=='') {
  347.     print "
  348. We do not find any php.exe, please select the php.exe folder (CLI is
  349. recommanded, usually in c:\php\cli\php.exe)
  350. ";
  351.     $php_bin_set = false;
  352. } elseif ( WINDOWS && !WEBINSTALLER && strlen($php_bin) ) {
  353.     $php_bin_sapi = win32DetectPHPSAPI();
  354.     $php_bin_set = true;
  355.     switch($php_bin_sapi){
  356.         case 'cli':
  357.         break;
  358.         case 'cgi':
  359.             print "
  360. *NOTICE*
  361. We found php.exe under $php_bin, it uses a $php_bin_sapi SAPI. PEAR commandline
  362. tool works well with it, if you have a CLI php.exe available, we
  363. recommand to use it.
  364. ";
  365.         break;
  366.         default:
  367.             print "
  368. *WARNING*
  369. We found php.exe under $php_bin, it uses an unknown SAPI. PEAR commandline
  370. tool has not been tested with it, if you have a CLI (or CGI) php.exe available,
  371. we strongly recommand to use it.
  372.  
  373. ";
  374.         break;
  375.     }
  376. }
  377.  
  378. ####
  379. # Temp stuff
  380. ####
  381.  
  382. $foo = tmp_dir();
  383. $ptmp = tempnam($foo, 'gope');
  384. if (WINDOWS) {
  385.     $ptmp = str_replace($foo,'',$ptmp);
  386.     $foo=str_replace("\\\\",'/',$foo);
  387.     $s = substr($ptmp,0,1);
  388.     if($s=="\\" || $s=='/' ){
  389.         $ptmp = $foo.'/'.substr($ptmp,1);
  390.     } else {
  391.         $ptmp = $foo.'/'.$ptmp;
  392.     }
  393. }
  394.  
  395. rm_rf($ptmp);
  396. mkdir_p($ptmp, 0700);
  397. $ok = @chdir($ptmp);
  398.  
  399. // If for some reason the user has no rights to access to
  400. // the standard tempdir, we assume that he has the right
  401. // to access his prefix and choose $prefix/tmp as tempdir
  402. if (!$ok) {
  403.     print "System's Tempdir failed, trying to use \$prefix/tmp ...";
  404.     $res = mkdir_p($prefix.'/tmp');
  405.     if (!$res) {
  406.         bail('mkdir '.$prefix.'/tmp'.' ... failed');
  407.     }
  408.     $ptmp = tempnam($prefix.'/tmp', 'gope');
  409.  
  410.     rm_rf($ptmp);
  411.     mkdir_p($ptmp, 0700);
  412.     $ok = @chdir($ptmp);
  413.  
  414.     if (!$ok) { // This should not happen, really ;)
  415.         bail('chdir '.$ptmp.' ... failed');
  416.     }
  417.  
  418.     print "ok\n";
  419.  
  420.     // Adjust TEMPDIR envvars
  421.     if (!isset($_ENV)) {
  422.         $_ENV = array();
  423.     };
  424.     $_ENV['TMPDIR'] = $_ENV['TEMP'] = $prefix.'/tmp';
  425. }
  426.  
  427. while (!WEBINSTALLER) {
  428.     print "
  429. Below is a suggested file layout for your new PEAR installation.  To
  430. change individual locations, type the number in front of the
  431. directory.  Type 'all' to change all of them or simply press Enter to
  432. accept these locations.
  433.  
  434. ";
  435.     if( WINDOWS && $php_bin=='' ){
  436.  
  437.     }
  438.     foreach ($config_vars as $n => $var) {
  439.         printf("%2d. $descfmt : %s\n", $n, $config_desc[$var], $$var);
  440.     }
  441.     print "\n$first-$last, 'all' or Enter to continue: ";
  442.     $tmp = trim(fgets($tty, 1024));
  443.     if ( empty($tmp) ) {
  444.         if( WINDOWS && !$php_bin_set ){
  445.             echo "**ERROR**
  446. Please, enter the php.exe path.
  447.  
  448. ";
  449.         } else {
  450.             break;
  451.         }
  452.     }
  453.     if (isset($config_vars[(int)$tmp])) {
  454.         $var = $config_vars[(int)$tmp];
  455.         $desc = $config_desc[$var];
  456.         $current = $$var;
  457.         if(WIN32GUI){
  458.             $tmp = win32BrowseForFolder("$desc [$current] :");
  459.         } else {
  460.             print "$desc [$current] : ";
  461.             $tmp = trim(fgets($tty, 1024));
  462.         }
  463.         $old = $$var;
  464.         if(WINDOWS && $var=='php_bin' ){
  465.             if(file_exists($tmp.DIRECTORY_SEPARATOR.'php.exe')){
  466.                 $tmp = $tmp.DIRECTORY_SEPARATOR.'php.exe';
  467.                 $php_bin_sapi = win32DetectPHPSAPI();
  468.                 if($php_bin_sapi=='cgi'){
  469.             print "
  470. ******************************************************************************
  471. NOTICE! We found php.exe under $php_bin, it uses a $php_bin_sapi SAPI.
  472. PEAR commandline tool works well with it.
  473. If you have a CLI php.exe available, we recommand to use it.
  474.  
  475. ";
  476.                 } elseif ($php_bin_sapi=='unknown') {
  477.             print "
  478. ******************************************************************************
  479. WARNING! We found php.exe under $php_bin, it uses an $php_bin_sapi SAPI.
  480. PEAR commandline tool has not been tested with it.
  481. If you have a CLI (or CGI) php.exe available, we strongly recommand to use it.
  482.  
  483. ";
  484.                 }
  485.                 echo "php.exe (sapi: $php_bin_sapi) found.\n\n";
  486.                 $php_bin_set = true;
  487.             } else {
  488.                 echo "**ERROR**: no php.exe found in this folder.\n";
  489.                 $tmp='';
  490.             }
  491.         }
  492.  
  493.         if (!empty($tmp) ) {
  494.             $$var = $tmp;
  495.         }
  496.     } elseif ($tmp == 'all') {
  497.         foreach ($config_vars as $n => $var) {
  498.             $desc = $config_desc[$var];
  499.             $current = $$var;
  500.             print "$desc [$current] : ";
  501.             $tmp = trim(fgets($tty, 1024));
  502.             if (!empty($tmp)) {
  503.                 $$var = $tmp;
  504.             }
  505.         }
  506.     }
  507. }
  508.  
  509. foreach ($config_vars as $n => $var) {
  510.     foreach ($config_vars as $m => $var2) {
  511.         $$var = str_replace('$'.$var2, $$var2, $$var);
  512.     }
  513. }
  514.  
  515. foreach ($config_vars as $var) {
  516.     $dir = $$var;
  517.     if (!preg_match('/_dir$/', $var)) {
  518.         continue;
  519.     };
  520.     if (!@is_dir($dir)) {
  521.         if (!mkdir_p($dir)) {
  522.             $root = WINDOWS ? 'administrator' : 'root';
  523.             bail("Unable to create {$config_desc[$var]} $dir.
  524. Run this script as $root or pick another location.\n");
  525.         }
  526.     }
  527. }
  528.  
  529. if (!WEBINSTALLER) {
  530.     $msg = "The following PEAR packages are bundled with PHP: " .
  531.         implode(', ', $pfc_packages);
  532.     print "\n" . wordwrap($msg, 75) . ".\n";
  533.     print "Would you like to install these as well? [Y/n] : ";
  534.     $install_pfc = !stristr(fgets($tty, 1024), "n");
  535.     print "\n";
  536. }
  537.  
  538. ####
  539. # Download
  540. ####
  541.  
  542. ini_set("include_path", $ptmp);
  543.  
  544. if (!extension_loaded('zlib') && !WEBINSTALLER) { // In Web context we could be in multithread env which makes dl() end up with a fatal error.
  545.     if (WINDOWS) {
  546.         @dl('php_zlib.dll');
  547.     } elseif (PHP_OS == 'HP-UX') {
  548.         @dl('zlib.sl');
  549.     } elseif (PHP_OS == 'AIX') {
  550.         @dl('zlib.a');
  551.     } else {
  552.         @dl('zlib.so');
  553.     }
  554. }
  555. if (!extension_loaded('zlib')) {
  556.     $urltemplate = 'http://pear.php.net/get/%s?uncompress=yes';
  557.     $have_gzip = false;
  558. } else {
  559.     $urltemplate = 'http://pear.php.net/get/%s';
  560.     $have_gzip = true;
  561. }
  562. print "Loading zlib: ".($have_gzip ? 'ok' : 'failed')."\n";
  563. if (!$have_gzip) {
  564.     print "Downloading uncompressed packages\n";
  565. };
  566.  
  567. if ($install_pfc) {
  568.     $to_install = array_merge($installer_packages, $pfc_packages);
  569. } else {
  570.     $to_install = $installer_packages;
  571. }
  572.  
  573. displayHTMLProgress($progress = 5);
  574.  
  575. if (file_exists(dirname(__FILE__).'/go-pear-bundle') || is_dir(dirname(__FILE__).'/go-pear-bundle')) {
  576.     $dh = @opendir(dirname(__FILE__).'/go-pear-bundle');
  577. }
  578. $local_dir = array();
  579. if ($dh) {
  580.     while($file = @readdir($dh)) {
  581.         if ($file == '.' || $file == '..' || !is_file(dirname(__FILE__).'/go-pear-bundle/'.$file)) {
  582.             continue;
  583.         };
  584.         $local_dir[] = $file;
  585.     };
  586. }
  587.  
  588. foreach ($installer_packages as $pkg) {
  589.     foreach($local_dir as $file) {
  590.         if (substr($file, 0, strlen($pkg)) == $pkg) {
  591.             echo str_pad("Using local package: $pkg", max(38,21+strlen($pkg)+4), '.');
  592.             copy(dirname(__FILE__).'/go-pear-bundle/'.$file, $file);
  593.             $tarball[$pkg] = $file;
  594.             echo "ok\n";
  595.             displayHTMLProgress($progress += round(65 / count($to_install)));
  596.             continue 2;
  597.         };
  598.     };
  599.  
  600.     $msg = str_pad("Downloading package: $pkg", max(38,21+strlen($pkg)+4), '.');
  601.     print $msg;
  602.     $url = sprintf($urltemplate, $pkg);
  603.     $tarball[$pkg] = download_url($url, null, $http_proxy);
  604.     print "ok\n";
  605.     displayHTMLProgress($progress += round(65 / count($to_install)));
  606. }
  607.  
  608. print 'Bootstrapping: PEAR...................';
  609. $r = 'RELEASE_' . ereg_replace('[^A-Za-z0-9]', '_', substr(substr($tarball['PEAR'], 5), 0, -4));
  610. $url = "http://cvs.php.net/co.php/php-src/pear/PEAR.php?p=1&r=$r";
  611. if (in_array('Getopt.php', $local_dir)) {
  612.     copy(dirname(__FILE__).'/go-pear-bundle/PEAR.php', 'PEAR.php');
  613.     echo "(local) ";
  614. } else {
  615.     download_url($url, 'PEAR.php', $http_proxy);
  616.     echo "(remote) ";
  617. }
  618.  
  619. include_once 'PEAR.php';
  620. print "ok\n";
  621.  
  622. print 'Bootstrapping: Archive_Tar............';
  623. $r = 'RELEASE_' . ereg_replace('[^A-Za-z0-9]', '_', substr(substr($tarball['Archive_Tar'], 12), 0, -4));
  624. $url = "http://cvs.php.net/co.php/pear/Archive_Tar/Archive/Tar.php?p=1&r=$r";
  625. mkdir('Archive', 0700);
  626.  
  627. if (in_array('Getopt.php', $local_dir)) {
  628.     copy(dirname(__FILE__).'/go-pear-bundle/Tar.php', 'Archive/Tar.php');
  629.     echo "(local) ";
  630. } else {
  631.     download_url($url, 'Archive/Tar.php', $http_proxy);
  632.     echo "(remote) ";
  633. }
  634. print "ok\n";
  635.  
  636. print 'Bootstrapping: Console_Getopt.........';
  637. $r = 'RELEASE_' . ereg_replace('[^A-Za-z0-9]', '_', substr(substr($tarball['Console_Getopt'], 15), 0, -4));
  638. $url = "http://cvs.php.net/co.php/php-src/pear/Console/Getopt.php?p=1&r=$r";
  639. mkdir('Console', 0700);
  640. if (in_array('Getopt.php', $local_dir)) {
  641.     copy(dirname(__FILE__).'/go-pear-bundle/Getopt.php', 'Console/Getopt.php');
  642.     echo "(local) ";
  643. } else {
  644.     download_url($url, 'Console/Getopt.php', $http_proxy);
  645.     echo "(remote) ";
  646. }
  647. print "ok\n";
  648.  
  649. if ($install_pfc) {
  650.     foreach ($pfc_packages as $pkg) {
  651.         foreach($local_dir as $file) {
  652.             if (substr($file, 0, strlen($pkg)) == $pkg) {
  653.                 echo str_pad("Using local package: $pkg", max(38,21+strlen($pkg)+4), '.');
  654.                 copy(dirname(__FILE__).'/go-pear-bundle/'.$file, $file);
  655.                 $tarball[$pkg] = $file;
  656.                 echo "ok\n";
  657.                 displayHTMLProgress($progress += round(65 / count($to_install)));
  658.                 continue 2;
  659.             };
  660.         };
  661.  
  662.         $msg = str_pad("Downloading package: $pkg", max(38,21+strlen($pkg)+4), '.');
  663.         print $msg;
  664.         $url = sprintf($urltemplate, $pkg);
  665.         $tarball[$pkg] = download_url($url, null, $http_proxy);
  666.         print "ok\n";
  667.         displayHTMLProgress($progress += round(65 / count($to_install)));
  668.     }
  669. }
  670.  
  671. displayHTMLProgress($progress = 70);
  672.  
  673. PEAR::setErrorHandling(PEAR_ERROR_DIE, "\n%s\n");
  674. print 'Extracting installer..................';
  675. $dot = strrpos($tarball['PEAR'], '.');
  676. $pkg = substr($tarball['PEAR'], 0, $dot);
  677. $ext = substr($tarball['PEAR'], $dot+1);
  678.  
  679. include_once 'Archive/Tar.php';
  680. $tar = &new Archive_Tar($tarball['PEAR'], $have_gzip);
  681. if (!$tar->extractModify($ptmp, $pkg)) {
  682.     bail("failed!\n");
  683. }
  684. print "ok\n";
  685.  
  686. $tarball['PEAR'] = 'package.xml'; // :-)
  687.  
  688. include_once "PEAR.php";
  689. include_once "PEAR/Config.php";
  690. include_once "PEAR/Command.php";
  691. include_once "PEAR/Registry.php";
  692.  
  693. if (WEBINSTALLER) {
  694.     $config = &PEAR_Config::singleton($prefix."/pear.conf", '');
  695. } else {
  696.     $config = &PEAR_Config::singleton();
  697. };
  698. $config->set('preferred_state', 'stable');
  699. foreach ($config_vars as $var) {
  700.     $config->set($var, $$var);
  701. }
  702.  
  703. $config->store();
  704.  
  705. $registry = new PEAR_Registry($php_dir);
  706. PEAR_Command::setFrontendType('CLI');
  707. $install = &PEAR_Command::factory('install', $config);
  708. $install_options = array(
  709.     'nodeps' => true,
  710.     'force' => true,
  711.     );
  712. foreach ($tarball as $pkg => $src) {
  713.     $options = $install_options;
  714.     if ($registry->packageExists($pkg)) {
  715.         $options['upgrade'] = true;
  716.     }
  717.  
  718.     $install->run('install', $options, array($src));
  719.  
  720.     displayHTMLProgress($progress += round(29 / count($tarball)));
  721. }
  722.  
  723. displayHTMLProgress($progress = 99);
  724.  
  725. // Base installation finished
  726.  
  727. ini_restore("include_path");
  728.  
  729. if (!WEBINSTALLER) {
  730.     $sep = WINDOWS ? ';' : ':';
  731.     $include_path = explode($sep, ini_get('include_path'));
  732.     if (WINDOWS) {
  733.         $found = false;
  734.         $t = strtolower($php_dir);
  735.         foreach($include_path as $path) {
  736.             if ($t==strtolower($path)) {
  737.                 $found = true;
  738.                 break;
  739.             }
  740.         }
  741.     } else {
  742.         $found = in_array($php_dir, $include_path);
  743.     }
  744.     if (!$found) {
  745.         print "
  746. ******************************************************************************
  747. WARNING!  The include_path defined in the currently used php.ini does not
  748. contain the PEAR PHP directory you just specified:
  749. <$php_dir>
  750. If the specified directory is also not in the include_path used by
  751. your scripts, you will have problems getting any PEAR packages working.
  752. ";
  753.  
  754.         if ( $php_ini = getPhpiniPath() ) {
  755.             print "\n\nWould you like to alter php.ini <$php_ini>? [Y/n] : ";
  756.             $alter_phpini = !stristr(fgets($tty, 1024), "n");
  757.             if( $alter_phpini ) {
  758.                 alterPhpIni($php_ini);
  759.             } else {
  760.                 if (WINDOWS) {
  761.                     print "
  762. Please look over your php.ini file to make sure
  763. $php_dir is in your include_path.";
  764.                 } else {
  765.                     print "
  766. I will add a workaround for this in the 'pear' command to make sure
  767. the installer works, but please look over your php.ini or Apache
  768. configuration to make sure $php_dir is in your include_path.
  769. ";
  770.                 }
  771.  
  772.             }
  773.         }
  774.  
  775.     print "
  776. Current include path           : ".ini_get('include_path')."
  777. Configured directory           : $php_dir
  778. Currently used php.ini (guess) : $php_ini
  779. ";
  780.  
  781.         print "Press Enter to continue: ";
  782.         fgets($tty, 1024);
  783.     }
  784.  
  785.     $pear_cmd = $bin_dir . DIRECTORY_SEPARATOR . 'pear';
  786.     $pear_cmd .= WINDOWS?'.bat':'';
  787.  
  788.     // check that the installed pear and the one in tha path are the same (if any)
  789.     $pear_old = which('pear', $bin_dir);
  790.     if ($pear_old && $pear_old != $pear_cmd) {
  791.         // check if it is a link or symlink
  792.         $islink = WINDOWS ? is_link($pear_old) : false;
  793.         if ($islink && readlink($pear_old) != $pear_cmd) {
  794.             print "\n** WARNING! The link $pear_old does not point to the " .
  795.                   "installed $pear_cmd\n";
  796.         } elseif (is_writable($pear_old)) {
  797.             rename($pear_old, "{$pear_old}_old");
  798.             print "\n** WARNING! Backed up old pear to {$pear_old}_old\n";
  799.         } else {
  800.             print "\n** WARNING! Old version found at $pear_old, please remove it or ".
  801.                   "be sure to use the new $pear_cmd command\n";
  802.         }
  803.     }
  804.  
  805.     print "\nThe 'pear' command is now at your service at $pear_cmd\n";
  806.  
  807.     // Alert the user if the pear cmd is not in PATH
  808.     $old_dir = $pear_old ? dirname($pear_old) : false;
  809.     if (!which('pear', $old_dir)) {
  810.         print "
  811. ** The 'pear' command is not currently in your PATH, so you need to
  812. ** use '$pear_cmd' until you have added
  813. ** '$bin_dir' to your PATH environment variable.
  814.  
  815. ";
  816.  
  817.     print "Run it without parameters to see the available actions, try 'pear list'
  818. to see what packages are installed, or 'pear help' for help.
  819.  
  820. For more information about PEAR, see:
  821.  
  822.   http://pear.php.net/faq.php
  823.   http://cvs.php.net/co.php/pearweb/doc/pear_package_manager.txt?p=1
  824.   http://pear.php.net/manual/
  825.  
  826. Thanks for using go-pear!
  827.  
  828. ";
  829.     }
  830. }
  831.  
  832. if (WEBINSTALLER) {
  833.     print "Writing WebFrontend file ... ";
  834.        @unlink($webfrontend_file); //Delete old one
  835.     copy ( $doc_dir.DIRECTORY_SEPARATOR.
  836.             'PEAR_Frontend_Web'.DIRECTORY_SEPARATOR.
  837.             'docs'.DIRECTORY_SEPARATOR.
  838.             'example.php',
  839.             $webfrontend_file
  840.         );
  841.     if ($_GET['step'] == 'install-progress') {
  842.         displayHTMLProgress($progress = 100);
  843.         ob_end_clean();
  844.         displayHTMLInstallationSummary();
  845.         displayHTMLFooter();
  846.     } else {
  847.         $out = ob_get_contents();
  848.  
  849.         $out = explode("\n", $out);
  850.         foreach($out as $line => $value) {
  851.             if (preg_match('/ok$/', $value)) {
  852.                 $value = preg_replace('/(ok)$/', '<span class="green">\1</span>', $value);
  853.             };
  854.             if (preg_match('/^install ok:/', $value)) {
  855.                 $value = preg_replace('/^(install ok:)/', '<span class="green">\1</span>', $value);
  856.             };
  857.             if (preg_match('/^Warning:/', $value)) {
  858.                 $value = '<span style="color: #ff0000">'.$value.'</span>';
  859.             };
  860.             $out[$line] = $value;
  861.         };
  862.         $out = nl2br(implode("\n",$out));
  863.         ob_end_clean();
  864.  
  865.         displayHTML('install', $out);
  866.     }
  867.     // Little hack, this will be fixed in PEAR later
  868.     if ( WINDOWS ) {
  869.         clearstatcache();
  870.         @unlink($bin_dir.DIRECTORY_SEPARATOR.'.tmppear');
  871.     }
  872.     exit;
  873. }
  874.  
  875. // Little hack, this will be fixed in PEAR later
  876. if ( WINDOWS ) {
  877.     clearstatcache();
  878.     @unlink($bin_dir.DIRECTORY_SEPARATOR.'.tmppear');
  879. }
  880.  
  881. if (WINDOWS && !WEBINSTALLER) {
  882.     win32CreateRegEnv();
  883. }
  884. // Set of functions following
  885.  
  886. // {{{ download_url()
  887.  
  888. function download_url($url, $destfile = null, $proxy = null)
  889. {
  890.     $use_suggested_filename = ($destfile === null);
  891.     if ($use_suggested_filename) {
  892.         $destfile = basename($url);
  893.     }
  894.     $tmp = parse_url($url);
  895.     if (empty($tmp['port'])) {
  896.         $tmp['port'] = 80;
  897.     }
  898.     if (empty($proxy)) {
  899.         $fp = fsockopen($tmp['host'], $tmp['port'], $errno, $errstr);
  900.         //print "\nconnecting to $tmp[host]:$tmp[port]\n";
  901.     } else {
  902.         $tmp_proxy = parse_url($proxy);
  903.         $phost     = $tmp_proxy['host'];
  904.         $pport     = $tmp_proxy['port'];
  905.         $fp = fsockopen($phost, $pport, $errno, $errstr);
  906.         //print "\nconnecting to $phost:$pport\n";
  907.     }
  908.     if (!$fp) {
  909.         bail("download of $url failed: $errstr ($errno)\n");
  910.     }
  911.     if (empty($proxy)) {
  912.         $path = $tmp['path'];
  913.     } else {
  914.         $path = "http://$tmp[host]:$tmp[port]$tmp[path]";
  915.     }
  916.     if (isset($tmp['query'])) {
  917.         $path .= "?$tmp[query]";
  918.     }
  919.     if (isset($tmp['fragment'])) {
  920.         $path .= "#$tmp[fragment]";
  921.     }
  922.     $request = "GET $path HTTP/1.0\r\nHost: $tmp[host]:$tmp[port]\r\n".
  923.         "User-Agent: go-pear\r\n";
  924.  
  925.     if (!empty($proxy) && $tmp_proxy['user'] != '') {
  926.         $request .= 'Proxy-Authorization: Basic ' .
  927.                     base64_encode($tmp_proxy['user'] . ':' . $tmp_proxy['pass']) . "\r\n";
  928. //        print "\nauthenticating against proxy with : user = ${tmp_proxy['user']} \n";
  929. //        print "and pass = ${tmp_proxy['pass']}\n";
  930.     } // if
  931.     $request .= "\r\n";
  932.     fwrite($fp, $request);
  933.     $cdh = "content-disposition:";
  934.     $cdhl = strlen($cdh);
  935.     $content_length = 0;
  936.     while ($line = fgets($fp, 2048)) {
  937.         if (trim($line) == '') {
  938.             break;
  939.         }
  940.         if (preg_match('/^Content-Length: (.*)$/i', $line, $matches)) {
  941.             $content_length = trim($matches[1]);
  942.         };
  943.         if ($use_suggested_filename && !strncasecmp($line, $cdh, $cdhl)) {
  944.             if (eregi('filename="([^"]+)"', $line, $matches)) {
  945.                 $destfile = basename($matches[1]);
  946.             }
  947.         }
  948.     }
  949.     if ($content_length) {
  950.         displayHTMLSetDownload($destfile);
  951.     };
  952.     $wp = fopen($destfile, "wb");
  953.     if (!$wp) {
  954.         bail("could not open $destfile for writing\n");
  955.     }
  956.     $bytes_read = 0;
  957.     $progress = 0;
  958.     while ($data = fread($fp, 2048)) {
  959.         fwrite($wp, $data);
  960.         $bytes_read += strlen($data);
  961.         if ($content_length != 0 && floor($bytes_read * 10 / $content_length) != $progress) {
  962.             $progress = floor($bytes_read * 10 / $content_length);
  963.             displayHTMLDownloadProgress($progress * 10);
  964.         };
  965.     }
  966.     fclose($fp);
  967.     fclose($wp);
  968.     return $destfile;
  969. }
  970.  
  971. // }}}
  972. // {{{ which()
  973.  
  974. function which($program, $dont_search_in = false)
  975. {
  976.     if (WINDOWS) {
  977.         if ($_path=my_env('Path')) {
  978.             $dirs = explode(';', $_path);
  979.         } else {
  980.             $dirs = explode(';', my_env('PATH'));
  981.         }
  982.         if ($dont_search_in &&
  983.             ($key = array_search($dont_search_in, $dirs)) !== false)
  984.         {
  985.             unset($dirs[$key]);
  986.         }
  987.  
  988.         foreach ($dirs as $dir) {
  989.             $tmp = "$dir\\$program";
  990.             if (file_exists($ret = "$tmp.exe") ||
  991.                 file_exists($ret = "$tmp.com") ||
  992.                 file_exists($ret = "$tmp.bat") ||
  993.                 file_exists($ret = "$tmp.cmd")) {
  994.                 return $ret;
  995.             }
  996.         }
  997.     } else {
  998.         $dirs = explode(':', my_env('PATH'));
  999.         if ($dont_search_in &&
  1000.             ($key = array_search($dont_search_in, $dirs)) !== false)
  1001.         {
  1002.             unset($dirs[$key]);
  1003.         }
  1004.         foreach ($dirs as $dir) {
  1005.             if (is_executable("$dir/$program")) {
  1006.                 return "$dir/$program";
  1007.             }
  1008.         }
  1009.     }
  1010.     return false;
  1011. }
  1012.  
  1013. // }}}
  1014. // {{{ bail()
  1015.  
  1016. function bail($msg = '')
  1017. {
  1018.     global $ptmp, $origpwd;
  1019.     if ($ptmp && is_dir($ptmp)) {
  1020.         chdir($origpwd);
  1021.         rm_rf($ptmp);
  1022.     }
  1023.     if ($msg && WEBINSTALLER) {
  1024.         $msg = @ob_get_contents() ."\n\n". $msg;
  1025.         @ob_end_clean();
  1026.         displayHTML('error', $msg);
  1027.         exit;
  1028.     };
  1029.     if ($msg && !WEBINSTALLER) {
  1030.         die($msg);
  1031.     }
  1032. }
  1033.  
  1034. // }}}
  1035. // {{{ mkdir_p()
  1036.  
  1037. function mkdir_p($dir, $mode = 0777)
  1038. {
  1039.     $lastdir = '';
  1040.     if (@is_dir($dir)) {
  1041.         return true;
  1042.     }
  1043.     $parent = dirname($dir);
  1044.     $parent_exists = (int)@is_dir($parent);
  1045.     $ok = true;
  1046.     if (!@is_dir($parent) && $parent != $dir) {
  1047.         $ok = mkdir_p(dirname($dir), $mode);
  1048.     }
  1049.     if ($ok) {
  1050.         $ok = @mkdir($dir, $mode);
  1051.         if (!$ok) {
  1052.             print "mkdir failed: $dir\n";
  1053.         }
  1054.     }
  1055.     return $ok;
  1056. }
  1057.  
  1058. // }}}
  1059. // {{{ rm_rf()
  1060.  
  1061. function rm_rf($path)
  1062. {
  1063.     if (@is_dir($path)) {
  1064.         $dp = opendir($path);
  1065.         while ($ent = readdir($dp)) {
  1066.             if ($ent == '.' || $ent == '..') {
  1067.                 continue;
  1068.             }
  1069.             $file = $path . DIRECTORY_SEPARATOR . $ent;
  1070.             if (@is_dir($file)) {
  1071.                 rm_rf($file);
  1072.             } else {
  1073.                 unlink($file);
  1074.             }
  1075.         }
  1076.         closedir($dp);
  1077.         return rmdir($path);
  1078.     } else {
  1079.         return @unlink($path);
  1080.     }
  1081. }
  1082.  
  1083. // }}}
  1084. // {{{ tmpdir()
  1085. /*
  1086.  * Fixes for winXP/wrong tmp set by Urs Gehrig (urs@circle.ch)
  1087.  */
  1088. function tmp_dir()
  1089. {
  1090.     if (WINDOWS){
  1091.         if ( my_env('TEMP') ) {
  1092.             $_temp = my_env('TEMP');
  1093.         } elseif ( my_env('TMP') ) {
  1094.             $_temp = my_env('TMP');
  1095.         } elseif ( my_env('windir') ) {
  1096.             $_temp = my_env('windir') . '\temp';
  1097.         } elseif ( my_env('SystemRoot') ) {
  1098.             $_temp = my_env('SystemRoot') . '\temp';
  1099.         }
  1100.  
  1101.         // handle ugly ENV var like \Temp instead of c:\Temp
  1102.         $dirs = explode("\\", realpath($_temp));
  1103.         if(strpos($_temp, ":") != 1) {
  1104.             unset($_temp);
  1105.             $_dirs = array();
  1106.             foreach($dirs as $key => $val) {
  1107.                 if((boolean)$val ) {
  1108.                     $_dirs[] = str_replace("/", "",  $val);
  1109.                 }
  1110.             }
  1111.             unset($dirs);
  1112.             $dirs = $_dirs;
  1113.             array_unshift ($dirs, "c:" );
  1114.             $_temp = $dirs[0];
  1115.             for($i = 1;$i < count($dirs);$i++) {
  1116.                 $_temp .= "//" . $dirs[$i];
  1117.             }
  1118.         }
  1119.         $ptmp = $_temp;
  1120.         return $_temp;
  1121.     }
  1122.     if (my_env('TMPDIR')) {
  1123.         return my_env('TMPDIR');
  1124.     }
  1125.     return '/tmp';
  1126. }
  1127.  
  1128. // }}}
  1129. // {{{ my_env()
  1130. /*
  1131. (cox) In my system PHP 4.2.1 (both cgi & cli) $_ENV is empty
  1132.       but getenv() does work fine
  1133. */
  1134. function my_env($var)
  1135. {
  1136.     if (is_array($_ENV) && isset($_ENV[$var])) {
  1137.         return $_ENV[$var];
  1138.     }
  1139.     return getenv($var);
  1140. }
  1141.  
  1142. // }}}
  1143. // {{{ detect_install_dirs()
  1144.  
  1145. function detect_install_dirs($_prefix = null) {
  1146.     global $prefix, $bin_dir, $php_dir, $php_bin, $doc_dir, $data_dir, $test_dir;
  1147.     if (WINDOWS) {
  1148.         if ($_prefix === null) {
  1149.             $prefix = getcwd();
  1150.         } else {
  1151.             $prefix = $_prefix;
  1152.         }
  1153.  
  1154.         if (!@is_dir($prefix)) {
  1155.             if (@is_dir('c:\php4')) {
  1156.                 $prefix = 'c:\php4';
  1157.             } elseif (@is_dir('c:\php')) {
  1158.                 $prefix = 'c:\php';
  1159.             }
  1160.         }
  1161.  
  1162.         $bin_dir   = '$prefix';
  1163.         $php_dir   = '$prefix\pear';
  1164.         $doc_dir   = '$php_dir\docs';
  1165.         $data_dir  = '$php_dir\data';
  1166.         $test_dir  = '$php_dir\tests';
  1167.         /*
  1168.          * Detects php.exe
  1169.          */
  1170.         if( $t=getenv('PHP_PEAR_PHP_BIN') ){
  1171.                 $php_bin   = $t;
  1172.         } elseif ($t=getenv('PHP_BIN') ) {
  1173.             $php_bin   = $t;
  1174.         } elseif ( $t=which('php') ) {
  1175.             $php_bin = $t;
  1176.         } elseif ( is_file($prefix.'\cli\php.exe') ) {
  1177.             $php_bin = $prefix.'\cli\php.exe';
  1178.         } elseif ( is_file($prefix.'\php.exe') ) {
  1179.             $php_bin = $prefix.'\php.exe';
  1180.         }
  1181.         if( $php_bin && !is_file($php_bin) ){
  1182.             $php_bin = '';
  1183.         } else {
  1184.             if(!ereg(":",$php_bin)){
  1185.                 $php_bin = getcwd().DIRECTORY_SEPARATOR.$php_bin;
  1186.             }
  1187.         }
  1188.         if (!is_file($php_bin)) {
  1189.             if (is_file('c:/php/cli/php.exe')) {
  1190.                 $php_bin = 'c:/php/cli/php.exe';
  1191.             } elseif (is_file('c:/php4/cli/php.exe')) {
  1192.                 $php_bin = 'c:/php4/cli/php.exe';
  1193.             }
  1194.         }
  1195.     } else {
  1196.         if ($_prefix === null) {
  1197.             $prefix    = dirname(PHP_BINDIR);
  1198.         } else {
  1199.             $prefix = $_prefix;
  1200.         }
  1201.         $bin_dir   = '$prefix/bin';
  1202.         $php_dir   = '$prefix/share/pear';
  1203.         $doc_dir   = '$php_dir/docs';
  1204.         $data_dir  = '$php_dir/data';
  1205.         $test_dir  = '$php_dir/tests';
  1206.         // check if the user has installed PHP with PHP or GNU layout
  1207.         if (@is_dir("$prefix/lib/php/.registry")) {
  1208.             $php_dir = '$prefix/lib/php';
  1209.         } elseif (@is_dir("$prefix/share/pear/lib/.registry")) {
  1210.             $php_dir = '$prefix/share/pear/lib';
  1211.             $doc_dir   = '$prefix/share/pear/docs';
  1212.             $data_dir  = '$prefix/share/pear/data';
  1213.             $test_dir  = '$prefix/share/pear/tests';
  1214.         } elseif (@is_dir("$prefix/share/php/.registry")) {
  1215.             $php_dir = '$prefix/share/php';
  1216.         }
  1217.     }
  1218. }
  1219.  
  1220. // }}}
  1221. // {{{ displayHTMLHeader
  1222.  
  1223. function displayHTMLHeader()
  1224. {
  1225. ?>
  1226. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  1227. <html>
  1228. <head>
  1229.  <title>PEAR :: Installer :: Go-PEAR</title>
  1230.  <style type="text/css">
  1231.  <!--
  1232.     a {
  1233.         color:#000000;
  1234.         text-decoration: none;
  1235.     }
  1236.     a:visited {
  1237.         color:#000000;
  1238.         text-decoration: none;
  1239.     }
  1240.     a:active {
  1241.         color:#000000;
  1242.         text-decoration: none;
  1243.     }
  1244.     a:hover {
  1245.         color:#000000;
  1246.         text-decoration: underline;
  1247.     }
  1248.  
  1249.     a.green {
  1250.         color:#006600;
  1251.         text-decoration: none;
  1252.     }
  1253.     a.green:visited {
  1254.         color:#006600;
  1255.         text-decoration: none;
  1256.     }
  1257.     a.green:active {
  1258.         color:#006600;
  1259.         text-decoration: none;
  1260.     }
  1261.     a.green:hover {
  1262.         color:#006600;
  1263.         text-decoration: underline;
  1264.     }
  1265.  
  1266.     body, td, th {
  1267.         font-family: verdana,arial,helvetica,sans-serif;
  1268.         font-size: 90%;
  1269.     }
  1270.  
  1271.     p {
  1272.         font-family: verdana,arial,helvetica,sans-serif;
  1273.     }
  1274.  
  1275.     th.pack {
  1276.         color: #FFFFFF;
  1277.         background: #009933;
  1278.         text-align: right;
  1279.     }
  1280.  
  1281.     td.package_info_title {
  1282.         color: #006600;
  1283.         font-weight: bold;
  1284.     }
  1285.  
  1286.     th.others {
  1287.         color: #006600;
  1288.         text-align: left;
  1289.     }
  1290.  
  1291.     em {
  1292.         font-weight: bold;
  1293.         font-style: italic;
  1294.     }
  1295.  
  1296.     .green {
  1297.         color: #006600;
  1298.     }
  1299.     .red {
  1300.         color: #006600;
  1301.     }
  1302.  
  1303.     span.headline {
  1304.         font-family: verdana,arial,helvetica,sans-serif;
  1305.         font-size: 125%;
  1306.         font-weight: bold;
  1307.         color: #ffffff;
  1308.     }
  1309.  
  1310.     span.title {
  1311.         font-family: verdana,arial,helvetica,sans-serif;
  1312.         font-size: 110%;
  1313.         font-weight: bold;
  1314.         color: #006600;
  1315.     }
  1316.  
  1317.     .newsDate {
  1318.         font-size: 85%;
  1319.         font-style: italic;
  1320.         color: #66cc66;
  1321.     }
  1322.  
  1323.     .compact {
  1324.         font-family: arial, helvetica, sans-serif;
  1325.         font-size: 90%;
  1326.     }
  1327.  
  1328.     .menuWhite {
  1329.         font-family: verdana,arial,helvetica,sans-serif;
  1330.         font-size: 75%;
  1331.         color: #ffffff;
  1332.     }
  1333.     .menuBlack {
  1334.         font-family: verdana,arial,helvetica,sans-serif;
  1335.         text-decoration: none;
  1336.         font-weight: bold;
  1337.         font-size: 75%;
  1338.         color: #000000;
  1339.     }
  1340.  
  1341.     .sidebar {
  1342.         font-size: 85%;
  1343.     }
  1344.  
  1345.     code, pre, tt {
  1346.         font-family: Courier, "Courier New", monospace;
  1347.         font-size: 90%;
  1348.     }
  1349.  
  1350.     pre.php {
  1351.         border-color:       black;
  1352.         border-style:       dashed;
  1353.         border-width:       1px;
  1354.         background-color:   #eeeeee;
  1355.         padding:            5px;
  1356.     }
  1357.  
  1358.     h1 {
  1359.         font-family: verdana,arial,helvetica,sans-serif;
  1360.         font-size: 140%;
  1361.         font-weight: bold;
  1362.         color: #006600;
  1363.     }
  1364.  
  1365.     h2 {
  1366.         font-family: verdana,arial,helvetica,sans-serif;
  1367.         font-size: 125%;
  1368.         font-weight: bold;
  1369.         color: #006600;
  1370.     }
  1371.  
  1372.     h3 {
  1373.         font-family: verdana,arial,helvetica,sans-serif;
  1374.         font-size: 110%;
  1375.         font-weight: bold;
  1376.         color: #006600;
  1377.     }
  1378.  
  1379.     small {
  1380.         font-family: verdana,arial,helvetica,sans-serif;
  1381.         font-size: 75%;
  1382.     }
  1383.  
  1384.     a.small {
  1385.         font-family: verdana,arial,helvetica,sans-serif;
  1386.         font-size: 75%;
  1387.         text-decoration: none;
  1388.     }
  1389.  
  1390.     .tableTitle {
  1391.         font-family: verdana,arial,helvetica,sans-serif;
  1392.         font-weight: bold;
  1393.     }
  1394.  
  1395.     .tableExtras {
  1396.         font-family: verdana,arial,helvetica,sans-serif;
  1397.         font-size: 85%;
  1398.         color: #FFFFFF;
  1399.     }
  1400.  
  1401.     input {
  1402.         font-family: verdana,arial,helvetica,sans-serif;
  1403.     }
  1404.  
  1405.     textarea {
  1406.         font-family: verdana,arial,helvetica,sans-serif;
  1407.     }
  1408.  
  1409.     input.small, select.small {
  1410.         font-family: verdana,arial,helvetica,sans-serif;
  1411.         font-size: 75%;
  1412.     }
  1413.  
  1414.     textarea.small {
  1415.         font-family: verdana,arial,helvetica,sans-serif;
  1416.         font-size: 75%;
  1417.     }
  1418.  
  1419.     form {
  1420.         margin-bottom : 0;
  1421.     }
  1422.  -->
  1423.  </style>
  1424.  <meta name="description" content="This is the Web Interface of the PEAR Installer" />
  1425. </head>
  1426.  
  1427. <body   topmargin="0" leftmargin="0"
  1428.         marginheight="0" marginwidth="0"
  1429.         bgcolor="#ffffff"
  1430.         text="#000000"
  1431.         link="#006600"
  1432.         alink="#cccc00"
  1433.         vlink="#003300"
  1434. >
  1435. <?php
  1436. }
  1437.  
  1438. // }}}
  1439. // {{{ displayHTML
  1440.  
  1441. function displayHTML($page = 'Welcome', $data = array())
  1442. {
  1443.     global $pfc_packages;
  1444.  
  1445.     displayHTMLHeader();
  1446.  
  1447. ?>
  1448. <a name="TOP" /></a>
  1449. <table border="0" cellspacing="0" cellpadding="0" height="48" width="100%">
  1450.   <tr bgcolor="#339900">
  1451.     <td align="left" width="120">
  1452.       <img src="<?php echo basename(__FILE__); ?>?action=img&img=pearlogo" width="104" height="50" vspace="2" hspace="5" alt="PEAR">
  1453.     </td>
  1454.     <td align="left" valign="middle" width="20">
  1455.        
  1456.     </td>
  1457.     <td align="left" valign="middle">
  1458.       <span class="Headline">Go-PEAR</span>
  1459.     </td>
  1460.   </tr>
  1461.  
  1462.   <tr bgcolor="#003300"><td colspan="3"></td></tr>
  1463.  
  1464.   <tr bgcolor="#006600">
  1465.     <td align="right" valign="top" colspan="3">
  1466.         <span style="color: #ffffff">Version <?php echo GO_PEAR_VER; ?></span> <br />
  1467.     </td>
  1468.   </tr>
  1469.  
  1470.   <tr bgcolor="#003300"><td colspan="3"></td></tr>
  1471. </table>
  1472.  
  1473.  
  1474. <table cellpadding="0" cellspacing="0" width="100%">
  1475.  <tr valign="top">
  1476.   <td bgcolor="#f0f0f0" width="100">
  1477.    <table width="200" border="0" cellpadding="4" cellspacing="0">
  1478.     <tr valign="top">
  1479.      <td style="font-size: 90%" align="left" width="200">
  1480.        <br><br>
  1481.        <img src="<?php echo basename(__FILE__); ?>?action=img&img=smallpear" border="0">
  1482.        <a href="<?php echo basename(__FILE__); ?>?step=Welcome&restart=1" <?php if ($page == 'Welcome') echo ' class="green"'; ?>>
  1483.          Welcome to Go-PEAR
  1484.        </a><br/>
  1485.  
  1486.        <img src="<?php echo basename(__FILE__); ?>?action=img&img=smallpear" border="0">
  1487.        <a href="<?php echo basename(__FILE__); ?>?step=config" <?php if ($page == 'config') echo ' class="green"'; ?>>
  1488.          Configuration
  1489.        </a><br/>
  1490.  
  1491.        <img src="<?php echo basename(__FILE__); ?>?action=img&img=smallpear" border="0">
  1492. <?php if ($page == 'install') echo '<span class="green">'; ?>
  1493.           Complete installtion<br/>
  1494. <?php if ($page == 'install') echo '</span>'; ?>
  1495.  
  1496.      </td>
  1497.     </tr>
  1498.    </table>
  1499.   </td>
  1500.   <td bgcolor="#cccccc" width="1" background="/gifs/checkerboard.gif"></td>
  1501.   <td>
  1502.    <table width="100%" cellpadding="10" cellspacing="0">
  1503.     <tr>
  1504.      <td valign="top">
  1505.  
  1506. <table border="0">
  1507. <tr>
  1508.   <td width="20">
  1509.   </td>
  1510.   <td>
  1511. <?php
  1512.     if ($page == 'error') {
  1513. ?>
  1514.             <span class="title">Error</span><br/>
  1515.             <br/>
  1516. <?php
  1517.         $value = $data;
  1518.         if (preg_match('/ok$/', $value)) {
  1519.             $value = preg_replace('/(ok)$/', '<span class="green">\1</span>', $value);
  1520.         }
  1521.         if (preg_match('/failed$/', $value)) {
  1522.             $value = preg_replace('/(failed)$/', '<span style="color: #ff0000">\1</span>', $value);
  1523.         }
  1524.         if (preg_match('/^install ok:/', $value)) {
  1525.             $value = preg_replace('/^(install ok:)/', '<span class="green">\1</span>', $value);
  1526.         }
  1527.         if (preg_match('/^Warning:/', $value)) {
  1528.             $value = '<span style="color: #ff0000">'.$value.'</span>';
  1529.         }
  1530.  
  1531.         echo nl2br($value);
  1532.     } elseif ($page == 'Welcome') {
  1533. ?>
  1534.             <span class="title">Welcome to go-pear <?php echo GO_PEAR_VER; ?>!</span><br/>
  1535.             <br/>
  1536.             Go-pear will install the Web Frontend of the PEAR Installer and all the needed <br/>
  1537.             files. This frontend is your tool for PEAR installation and maintenance.<br/>
  1538.             <br/>
  1539.             Go-pear also lets you download and install the PEAR packages bundled<br/>
  1540.             with PHP: <?php echo implode(', ', $GLOBALS['pfc_packages']); ?>.<br/>
  1541.             <br/>
  1542.             <a href="<?php echo basename(__FILE__); ?>?step=config" class="green">Next >></a>
  1543. <?php
  1544.     } elseif ($page == 'config') {
  1545.         if (!empty($GLOBALS['http_proxy'])) {
  1546.             list($proxy_host, $proxy_port) = explode(':', $GLOBALS['http_proxy']);
  1547.         } else {
  1548.             $proxy_host = $proxy_port = '';
  1549.         }
  1550. ?>
  1551.             <form action="<?php echo basename(__FILE__);?>?step=install" method="post">
  1552.             <span class="title">Configuration</span><br/>
  1553.             <br/>
  1554.             HTTP proxy (host:port):
  1555.             <input type="text" name="proxy[host]" value="<?php echo $proxy_host;?>">
  1556.             <input type="text" name="proxy[port]" value="<?php echo $proxy_port;?>" size="6">
  1557.             <br/><br/><hr/><br/>
  1558.             Below is a suggested file layout for your new PEAR installation. <br/>
  1559.             <br/>
  1560.             <table border="0">
  1561.               <TR>
  1562.                 <TD valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&img=note" border="0"></TD>
  1563.                 <TD>
  1564.                     <span class="green">
  1565.                     <b>Note:</b> Make sure that PHP has the permission to access the specified<br/>
  1566.                     directories.<br/><br/>
  1567.                   </span>
  1568.                 </TD>
  1569.               </TR>
  1570.             </table>
  1571.             <TABLE border="0">
  1572. <?php
  1573.     // Display error messages
  1574.         if (isset($GLOBALS['www_errors']) && sizeof($GLOBALS['www_errors']) ) {
  1575.             $www_errors = $GLOBALS['www_errors'];
  1576.             echo "<tr><td>";
  1577.             echo '<span class="red">ERROR(S):</span>';
  1578.             echo "</td></tr>";
  1579.             foreach ($www_errors as $n => $var) {
  1580.                 echo "<tr><td>";
  1581.                 echo '<span class="red">'.$GLOBALS['config_desc'][$n].': </span>';
  1582.                 echo "</td><td>";
  1583.                 echo '<span class="red">'.$www_errors[$n].'</span>';
  1584.                 echo "<br>\n";
  1585.                 echo "</td></tr>\n";
  1586.             }
  1587.         }
  1588.  
  1589.         foreach ($GLOBALS['config_vars'] as $n => $var) {
  1590.             printf('<tr><td>%d. %s</td><td><input type="text" name="config[%s]" value="%s"></td></tr>',
  1591.             $n,
  1592.             $GLOBALS['config_desc'][$var],
  1593.             $var,
  1594.             $GLOBALS[$var]);
  1595.         }
  1596. ?>
  1597.             </TABLE>
  1598.             <br/><hr/><br/>
  1599.             The following PEAR packages are common ones, and can be installed<br/>
  1600.             by go-pear too: <br/>
  1601. <?php    echo implode(', ', $GLOBALS['pfc_packages']);?>            .<br/>
  1602.             <input type="checkbox" name="install_pfc" <?php if($GLOBALS['install_pfc']) echo 'checked';?>> Install those too<br/>
  1603.             <br/><br/>
  1604.             <table border="0">
  1605.               <TR>
  1606.                 <TD valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&img=note" border="0"></TD>
  1607.                 <TD>
  1608.                     <span class="green">
  1609.                       <b>Note:</b> Installation might take some time, because go-pear has to download<br/>
  1610.                       all needed files from pear.php.net. Just be patient and wait for the next<br/>
  1611.                       page to load.<br/>
  1612.                   </span>
  1613.                 </TD>
  1614.               </TR>
  1615.             </table>
  1616.             <br>
  1617.             <input type="checkbox" name="BCmode" id="BCmode" checked> Compatibility-Mode for old non-DOM Browsers<br/>
  1618.             <script type="text/javascript">
  1619.             <!--
  1620.                 if (document.getElementById('BCmode')) {
  1621.                     document.getElementById('BCmode').checked = 0;
  1622.                 };
  1623.             // -->
  1624.             </script>
  1625.  
  1626. <?php
  1627.         if (WINDOWS && phpversion() == '4.1.1') {
  1628. ?>
  1629.                     <table border="0">
  1630.                       <TR>
  1631.                         <TD valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&img=note" border="0"></TD>
  1632.                         <TD>
  1633.                             <span style="color: #ff0000">
  1634.                               <b>Warning:</b> Your PHP version (4.1.1) might be imcompatible with go-pear due to a bug<br/>
  1635.                               in your PHP binary. If the installation crashes you might want to update your PHP version.</br>
  1636.                           </span>
  1637.                         </TD>
  1638.                       </TR>
  1639.                     </table>
  1640. <?php
  1641.         }
  1642. ?>
  1643.             <br/>
  1644.             <input type="submit" value="Install" onClick="javascript: submitButton.value='Downloading and installing ... please wait ...'" name="submitButton">
  1645.             </form>
  1646. <?php
  1647.     } elseif ($page == 'install') {
  1648. ?>
  1649.             <span class="title">Installation Complete - Summary</span><br/>
  1650. <?php
  1651.         displayHTMLInstallationSummary($data);
  1652.     } elseif ($page == 'preinstall') {
  1653. ?>
  1654.             <span class="title">Installation in progress ...</span><br/>
  1655.             <br/>
  1656.             <script language="javascript">
  1657.             <!--
  1658.  
  1659.                 var progress;
  1660.                 var downlodprogress;
  1661.                 progress = 0;
  1662.                 downloadprogress = 0;
  1663.  
  1664.                 function setprogress(value)
  1665.                 {
  1666.                     progress = value;
  1667.  
  1668.                     prog = document.getElementById('installation_progress');
  1669.                     prog.innerHTML = progress + " %";
  1670.                     progress2 = progress / 10;
  1671.                     progress2 = Math.floor(progress2);
  1672.                     for (i=0; i < 10; i++)
  1673.                         document.getElementById('progress_cell_'+i).style.backgroundColor = "#cccccc";
  1674.                     switch(progress2)
  1675.                     {
  1676.                         case 10:
  1677.                             document.getElementById('progress_cell_9').style.backgroundColor = "#006600";
  1678.                         case  9:
  1679.                             document.getElementById('progress_cell_8').style.backgroundColor = "#006600";
  1680.                         case  8:
  1681.                             document.getElementById('progress_cell_7').style.backgroundColor = "#006600";
  1682.                         case  7:
  1683.                             document.getElementById('progress_cell_6').style.backgroundColor = "#006600";
  1684.                         case  6:
  1685.                             document.getElementById('progress_cell_5').style.backgroundColor = "#006600";
  1686.                         case  5:
  1687.                             document.getElementById('progress_cell_4').style.backgroundColor = "#006600";
  1688.                         case  4:
  1689.                             document.getElementById('progress_cell_3').style.backgroundColor = "#006600";
  1690.                         case  3:
  1691.                             document.getElementById('progress_cell_2').style.backgroundColor = "#006600";
  1692.                         case  2:
  1693.                             document.getElementById('progress_cell_1').style.backgroundColor = "#006600";
  1694.                         case  1:
  1695.                             document.getElementById('progress_cell_0').style.backgroundColor = "#006600";
  1696.                     };
  1697.                 }
  1698.  
  1699.                 function addprogress(value)
  1700.                 {
  1701.                     progress += value;
  1702.                     setprogress(progress);
  1703.                 }
  1704.  
  1705.                 function setdownloadfile(value)
  1706.                 {
  1707.                     setdownloadprogress(0);
  1708.  
  1709.                     prog = document.getElementById('download_file');
  1710.                     prog.innerHTML = 'Downloading '+value+' ...';
  1711.                 };
  1712.  
  1713.                 function setdownloadprogress(value)
  1714.                 {
  1715.                     downloadprogress = value;
  1716.  
  1717.                     prog = document.getElementById('download_progress');
  1718.                     prog.innerHTML = downloadprogress + " %";
  1719.                     progress2 = downloadprogress / 10;
  1720.                     progress2 = Math.floor(progress2);
  1721.                     for (i=0; i < 10; i++)
  1722.                         document.getElementById('download_progress_cell_'+i).style.backgroundColor = "#cccccc";
  1723.                     switch(progress2)
  1724.                     {
  1725.                         case 10:
  1726.                             document.getElementById('download_progress_cell_9').style.backgroundColor = "#006600";
  1727.                         case  9:
  1728.                             document.getElementById('download_progress_cell_8').style.backgroundColor = "#006600";
  1729.                         case  8:
  1730.                             document.getElementById('download_progress_cell_7').style.backgroundColor = "#006600";
  1731.                         case  7:
  1732.                             document.getElementById('download_progress_cell_6').style.backgroundColor = "#006600";
  1733.                         case  6:
  1734.                             document.getElementById('download_progress_cell_5').style.backgroundColor = "#006600";
  1735.                         case  5:
  1736.                             document.getElementById('download_progress_cell_4').style.backgroundColor = "#006600";
  1737.                         case  4:
  1738.                             document.getElementById('download_progress_cell_3').style.backgroundColor = "#006600";
  1739.                         case  3:
  1740.                             document.getElementById('download_progress_cell_2').style.backgroundColor = "#006600";
  1741.                         case  2:
  1742.                             document.getElementById('download_progress_cell_1').style.backgroundColor = "#006600";
  1743.                         case  1:
  1744.                             document.getElementById('download_progress_cell_0').style.backgroundColor = "#006600";
  1745.                     };
  1746.                 };
  1747.  
  1748.             // -->
  1749.             </script>
  1750.             <table style="border-width: 1px; border-color: #000000" cellspacing="0" cellpadding="0">
  1751.             <tr>
  1752.               <td>
  1753.                 <table border="0">
  1754.                   <tr>
  1755.                     <td bgcolor="#cccccc" width="10" height="20" id="progress_cell_0"> </td>
  1756.                     <td bgcolor="#cccccc" width="10" height="20" id="progress_cell_1"> </td>
  1757.                     <td bgcolor="#cccccc" width="10" height="20" id="progress_cell_2"> </td>
  1758.                     <td bgcolor="#cccccc" width="10" height="20" id="progress_cell_3"> </td>
  1759.                     <td bgcolor="#cccccc" width="10" height="20" id="progress_cell_4"> </td>
  1760.                     <td bgcolor="#cccccc" width="10" height="20" id="progress_cell_5"> </td>
  1761.                     <td bgcolor="#cccccc" width="10" height="20" id="progress_cell_6"> </td>
  1762.                     <td bgcolor="#cccccc" width="10" height="20" id="progress_cell_7"> </td>
  1763.                     <td bgcolor="#cccccc" width="10" height="20" id="progress_cell_8"> </td>
  1764.                     <td bgcolor="#cccccc" width="10" height="20" id="progress_cell_9"> </td>
  1765.                     <td bgcolor="#ffffff" width="10" height="20"> </td>
  1766.                     <td bgcolor="#ffffff" height="20" id="installation_progress" class="green">0 %</td>
  1767.                   </tr>
  1768.                 </table>
  1769.                 <br>
  1770.                 <table border="0">
  1771.                   <tr>
  1772.                     <td bgcolor="#cccccc" width="10" height="20" id="download_progress_cell_0"> </td>
  1773.                     <td bgcolor="#cccccc" width="10" height="20" id="download_progress_cell_1"> </td>
  1774.                     <td bgcolor="#cccccc" width="10" height="20" id="download_progress_cell_2"> </td>
  1775.                     <td bgcolor="#cccccc" width="10" height="20" id="download_progress_cell_3"> </td>
  1776.                     <td bgcolor="#cccccc" width="10" height="20" id="download_progress_cell_4"> </td>
  1777.                     <td bgcolor="#cccccc" width="10" height="20" id="download_progress_cell_5"> </td>
  1778.                     <td bgcolor="#cccccc" width="10" height="20" id="download_progress_cell_6"> </td>
  1779.                     <td bgcolor="#cccccc" width="10" height="20" id="download_progress_cell_7"> </td>
  1780.                     <td bgcolor="#cccccc" width="10" height="20" id="download_progress_cell_8"> </td>
  1781.                     <td bgcolor="#cccccc" width="10" height="20" id="download_progress_cell_9"> </td>
  1782.                     <td bgcolor="#ffffff" width="10" height="20"> </td>
  1783.                     <td bgcolor="#ffffff" height="20" id="download_progress" class="green">0 %</td>
  1784.                     <td bgcolor="#ffffff" width="10" height="20"> </td>
  1785.                     <td bgcolor="#ffffff" height="20" id="download_file" class="green"></td>
  1786.                   </tr>
  1787.                 </table>
  1788.                 <br>
  1789.                 <iframe src="<?php echo basename(__FILE__); ?>?step=install-progress&<?php echo SID;?>" width="700" height="700" frameborder="0" marginheight="0" marginwidth="0"></iframe>
  1790.               </td>
  1791.             </tr>
  1792.             </table>
  1793. <?php
  1794.     }
  1795. ?>
  1796.   </td>
  1797. </tr>
  1798. </table>
  1799.  
  1800.  
  1801. </td>
  1802.     </tr>
  1803.    </table>
  1804.   </td>
  1805.  
  1806.  </tr>
  1807. </table>
  1808. <?php
  1809.     displayHTMLFooter();
  1810. }
  1811.  
  1812. // }}}
  1813. // {{{ displayHTMLFooter
  1814.  
  1815. function displayHTMLFooter()
  1816. {
  1817.     ?>
  1818.     </body>
  1819.     </html>
  1820.     <?php
  1821. };
  1822.  
  1823. // }}}
  1824. // {{{ displayHTMLInstallationSummary
  1825.  
  1826. function displayHTMLInstallationSummary($data = '')
  1827. {
  1828.     $next     = NULL;
  1829.     $prefix   = dirname($GLOBALS['webfrontend_file']);
  1830.     $doc_root = strip_magic_quotes($_SERVER['DOCUMENT_ROOT']);
  1831.     $file_dir = dirname(__FILE__);
  1832.     if ( WINDOWS ) {
  1833.         $prefix   = str_replace('/', '\\', strtolower($prefix));
  1834.         $doc_root = str_replace('/', '\\', strtolower($doc_root));
  1835.         $file_dir = str_replace('/', '\\', strtolower($file_dir));
  1836.     }
  1837.  
  1838.     if ($doc_root && substr($prefix, 0, strlen($doc_root)) == $doc_root) {
  1839.         $next = substr($prefix, strlen($doc_root)).'/index.php';
  1840.     } else if ($file_dir && substr($prefix, 0, strlen($file_dir)) == $file_dir) {
  1841.         $next = substr($prefix, strlen($file_dir)).'/index.php';
  1842.     }
  1843.  
  1844.     if ($data) {
  1845.         echo "<br/>".$data;
  1846.     }
  1847. ?>
  1848.             <br/>
  1849.             <table border="0">
  1850.               <TR>
  1851.                 <TD valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&img=note" border="0"></TD>
  1852.                 <TD>
  1853.                     <span class="green">
  1854.                   <b>Note:</b> To use PEAR without any problems you need to add your<br/>
  1855.                   PEAR Installation path (<?php echo $GLOBALS['php_dir']; ?>)<br>
  1856.                   to your <a href="http://www.php.net/manual/en/configuration.directives.php#ini.include_path">include_path</a>.<br/>
  1857.                       <br/>
  1858.                   Using a .htaccess file or directly edit httpd.conf would be working solutions<br/>
  1859.                   for Apache running servers, too.<br/>
  1860.                   </span>
  1861.                 </TD>
  1862.               </TR>
  1863.             </table>
  1864.             <br/>
  1865.             For more information about PEAR, see:<br/>
  1866.             <a href="http://pear.php.net/faq.php" target="_new" class="green">PEAR FAQ</a><br/>
  1867.             <a href="http://pear.php.net/manual/" target="_new" class="green">PEAR Manual</a><br/>
  1868.             <br/>
  1869.             Thanks for using go-pear!<br/>
  1870.             <br/>
  1871. <?php
  1872.     if ($next === NULL) {
  1873. ?>
  1874.                     <table border="0">
  1875.                       <TR>
  1876.                         <TD valign="top"><img src="<?php echo basename(__FILE__); ?>?action=img&img=note" border="0"></TD>
  1877.                         <TD>
  1878.                             <span style="color: #ff0000">
  1879.                             <b>Warning:</b> Go-PEAR was not able to determine the URL to the newly<br/>
  1880.                             installed Web Frontend of the PEAR Installer. Please access it manually.<br/>
  1881.                             Since you specified the prefix, you should know how to do so.<br/>
  1882.                           </span>
  1883.                         </TD>
  1884.                       </TR>
  1885.                     </table>
  1886. <?php
  1887.     } else {
  1888.         if ($_GET['step'] == 'install-progress') {
  1889. ?>
  1890.                         <a href="<?php echo $next;?>" class="green" target="_parent">Start Web Frontend of the PEAR Installer >></a>
  1891. <?php
  1892.         } else {
  1893. ?>
  1894.                         <a href="<?php echo $next;?>" class="green">Start Web Frontend of the PEAR Installer >></a>
  1895. <?php
  1896.         }
  1897.     }
  1898. }
  1899.  
  1900. // }}}
  1901. // {{{ strip_magic_quotes
  1902.  
  1903. function strip_magic_quotes($value)
  1904. {
  1905.     if (ini_get('magic_quotes_gpc')) {
  1906.         return stripslashes($value);
  1907.     }
  1908.     return $value;
  1909. };
  1910.  
  1911. // }}}
  1912. // {{{ showImage
  1913.  
  1914. function showImage($img)
  1915. {
  1916.     $images = array(
  1917.         'smallpear' => array(
  1918.             'type' => 'gif',
  1919.             'data' => 'R0lGODlhEQATAMQAAAAAACqUACiTAC2WAC+YAzKZBTSaBsHgszOZADCYADmcB4TCZp3Ohtfrzd/v1+by4PD47DaaAz+fDUijF2WyOlCoHvT58VqtJPn893y+S/v9+f7//f3+/Pz9+////////ywAAAAAEQATAAAFkqAnjiR5NGXqcdpCoapnMVRdWbEHUROVVROYalHJTCaVAKWTcjAUGckgQY04SJAFMhJJIL5e4a5I6X6/gwlkRIwOzucAY9SYZBRvOCKheIwYFxR5enxCLhVeemAHbBQVg4SMIoCCinsKVyIOdlKKAhQcJFpGiWgFQiIYPxeJCQEEcykcDIgDAwYUkjEWB70NGykhADs=',
  1920.             ),
  1921.         'pearlogo' => array(
  1922.             'type' => 'gif',
  1923.             'data' => 'R0lGODlhaAAyAMT/AMDAwP3+/TWaAvD47Pj89vz++zebBDmcBj6fDEekFluvKmu3PvX68ujz4XvBS8LgrNXqxeHw1ZnPaa/dgvv9+cLqj8LmltD2msnuls3xmszwmf7+/f///wAAAAAAAAAAACH5BAEAAAAALAAAAABoADIAQAX/ICCOZGmeaKqubOtWWjwJphLLgH1XUu//C1Jisfj9YLEKQnSY3GaixWQqQTkYHM4AMulNLJFC9pEwIW/odKU8cqTfsWoTTtcomU4ZjbR4ZP+AgYKCG0EiZ1AuiossEhwEXRMEg5SVWQ6MmZqKWD0QlqCUEHubpaYlExwRPRZioZZVp7KzKQoSDxANDLsNXA5simd2FcQYb4YAc2jEU80TmAAIztPCMcjKdg4OEsZJmwIWWQPQI4ikIwtoVQnddgrv8PFlCWgYCwkI+fp5dkvJ/IlUKMCy6tYrDhNIIKLFEAWCTxse+ABD4SClWA0zovAjcUJFi6EwahxZwoGqHhFA/4IqoICkyxQSKkbo0gDkuBXV4FRAJkRCnTgi2P28IcEfk5xpWppykFJVuScmEvDTEETAVJ6bEpypcADPkz3pvKVAICHChkC7siQ08zVqu4Q6hgIFEFZuEn/KMgRUkaBmAQs+cEHgIiHVH5EAFpIgW4+NT6LnaqhDwe/Ov7YOmWZp4MkiAWBIl0kAVsJWuzcYpdiNgddc0E8cKBAu/FElBwagMb88ZZKDRAkWJtkWhHh3wwUbKHQJN3wQAaXGR2LpArv5oFHRR34C7Mf6oLXZNfqBgNI7oOLhj1f8PaGpygHQ0xtP8MDVKwYTSKcgxr9/hS6/pCCAAg5M4B9/sWh1YP9/XSgQWRML/idBfKUc4IBET9lFjggKhDYZAELZJYEBI2BDB3ouNBEABwE8gAwiCcSYgAKqPdEVAG7scM8BPPZ4AIlM+OgjAgpMhRE24OVoBwsIFEGFA7ZkQQBWienWxmRa7XDjKZXhBdAeSmKQwgLuUVLICa6VEKIGcK2mQWoVZHCBXJblJUFkY06yAXlGsPIHBEYdYiWHb+WQBgaIJqqoHFNpgMGB7dT5ZQuG/WbBAIAUEEFNfwxAWpokTIXJAWdgoJ9kRFG2g5eDRpXSBpEIF0oEQFaZhDbaSFANRgqcJoEDRARLREtxOQpsPO906ZUeJgjQB6dZUPBAdwcF8KLXXRVQaKFcsRRLJ6vMiiCNKxRE8ECZKgUA3Va4arOAAqdGRWO7uMZH5AL05gvsjQbg6y4NCjQ1kw8TVGcbdoKGKx8j3bGH7nARBArqwi0gkFJBrZiXBQRbHoIgnhSjcEBKfD7c3HMhz+JIQSY3t8GGKW+SUhfUajxGzKd0IoHBNkNQK86ZYEqdzYA8AHQpqXRUm80oHs1CAgMoBxzRqvzs9CIKECC1JBp7enUpfXHApwVYNAfo16c4IrYPLVdSAJVob7IAtCBFQGHcs/RRdiUDPHA33oADEAIAOw==',
  1924.             ),
  1925.         'note' => array(
  1926.             'type' => 'png',
  1927.             'data' => 'iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAAAAADFHGIkAAAAAmJLR0QAAKqNIzIAAAEESURBVHjaZZIhksMwDEV9voWFSwsLA0MLDf8VdARBUUNBQ1FBHcErZ5M0baXJjOPnb0vfLuMMn3H+lWMgBKL89A1Eq9Q9IrwB+gIOsnMPBR8giMclguQfBGS8x5xIoPQxnxqb4LL/eQ4l2AVNONP2ZshLCqJ3qqzWtT5pNgNnLU4OcNbuiqaLmFmHGhJ0TCMC99+f2wphlhaOYjuQVc0IIzLH2BRWfQoWsNSjct8AVop4rF3belTuVAb3MRj6kLrcTwtIy+g03V1vC57t1XrMzqfP5pln5yLTkk7+5UhstvOni1X3ixLEdf2c36+W0Q7kOb48hnSRLI/XdNPfX4kpMkgP5R+elfdkDPprQgAAAEN0RVh0U29mdHdhcmUAQCgjKUltYWdlTWFnaWNrIDQuMi44IDk5LzA4LzAxIGNyaXN0eUBteXN0aWMuZXMuZHVwb250LmNvbZG6IbgAAAAqdEVYdFNpZ25hdHVyZQAzYmQ3NDdjNWU0NTgwNzAwNmIwOTBkZDNlN2EyNmM0NBTTk/oAAAAOdEVYdFBhZ2UAMjR4MjQrMCswclsJMQAAAABJRU5ErkJggg==',
  1928.             ),
  1929.         );
  1930.  
  1931.     Header('Content-Type: image/'.$images[$img]['type']);
  1932.     echo base64_decode($images[$img]['data']);
  1933. };
  1934.  
  1935. // }}}
  1936. // {{{ displayHTMLProgress
  1937.  
  1938. function displayHTMLProgress($progress)
  1939. {
  1940.     if (!(WEBINSTALLER && isset($_SESSION['go-pear']['DHTML']) && $_SESSION['go-pear']['DHTML'])) {
  1941.         return;
  1942.     };
  1943.     $msg = ob_get_contents();
  1944.     ob_end_clean();
  1945.  
  1946.     $msg = explode("\n", $msg);
  1947.     foreach($msg as $key => $value) {
  1948.         if (preg_match('/ok$/', $value)) {
  1949.             $value = preg_replace('/(ok)$/', '<span class="green">\1</span>', $value);
  1950.         };
  1951.         if (preg_match('/failed$/', $value)) {
  1952.             $value = preg_replace('/(failed)$/', '<span style="color: #ff0000">\1</span>', $value);
  1953.         };
  1954.         if (preg_match('/^install ok:/', $value)) {
  1955.             $value = preg_replace('/^(install ok:)/', '<span class="green">\1</span>', $value);
  1956.         };
  1957.         if (preg_match('/^Warning:/', $value)) {
  1958.             $value = '<span style="color: #ff0000">'.$value.'</span>';
  1959.         };
  1960.         $msg[$key] = $value;
  1961.     };
  1962.     $msg = implode('<br>', $msg);
  1963.  
  1964.     $msg.='<script type="text/javascript"> parent.setprogress('.((int) $progress).');  </script>';
  1965.  
  1966.     echo $msg;
  1967.     ob_start();
  1968. };
  1969.  
  1970. // }}}
  1971. // {{{ displayHTMLDownloadProgress
  1972.  
  1973. function displayHTMLDownloadProgress($progress)
  1974. {
  1975.     if (!(WEBINSTALLER && isset($_SESSION['go-pear']['DHTML']) && $_SESSION['go-pear']['DHTML'])) {
  1976.         return;
  1977.     };
  1978.     $msg = ob_get_contents();
  1979.     ob_end_clean();
  1980.  
  1981.     echo '<script type="text/javascript"> parent.setdownloadprogress('.((int) $progress).');  </script>';
  1982.  
  1983.     ob_start();
  1984.     echo $msg;
  1985. };
  1986.  
  1987. // }}}
  1988. // {{{ displayHTMLSetDownload
  1989.  
  1990. function displayHTMLSetDownload($file)
  1991. {
  1992.     if (!(WEBINSTALLER && isset($_SESSION['go-pear']['DHTML']) && $_SESSION['go-pear']['DHTML'])) {
  1993.         return;
  1994.     };
  1995.     $msg = ob_get_contents();
  1996.     ob_end_clean();
  1997.  
  1998.     echo '<script type="text/javascript"> parent.setdownloadfile("'.$file.'");  </script>';
  1999.  
  2000.     ob_start();
  2001.     echo $msg;
  2002. };
  2003.  
  2004. // }}}
  2005. // {{{ win32BrowseForFolder
  2006.  
  2007. /*
  2008.  * Create a vbs script to browse the getfolder dialog, called
  2009.  * by cscript, if it's available.
  2010.  * $label is the label text in the header of the dialog box
  2011.  *
  2012.  * TODO:
  2013.  * - Do not show Control panel
  2014.  * - Replace WSH with calls to w32 as soon as callbacks work
  2015.  * @Author Pierrre-Alain Joye
  2016.  */
  2017. function win32BrowseForFolder ( $label )
  2018. {
  2019.     global $ptmp;
  2020.     static $wshSaved=false;
  2021.     static $cscript='';
  2022. $wsh_browserfolder = 'Option Explicit
  2023. Dim ArgObj, var1, var2, sa, sFld
  2024. Set ArgObj = WScript.Arguments
  2025. Const BIF_EDITBOX = &H10
  2026. Const BIF_NEWDIALOGSTYLE = &H40
  2027. Const BIF_RETURNONLYFSDIRS   = &H0001
  2028. Const BIF_DONTGOBELOWDOMAIN  = &H0002
  2029. Const BIF_STATUSTEXT         = &H0004
  2030. Const BIF_RETURNFSANCESTORS  = &H0008
  2031. Const BIF_VALIDATE           = &H0020
  2032. Const BIF_BROWSEFORCOMPUTER  = &H1000
  2033. Const BIF_BROWSEFORPRINTER   = &H2000
  2034. Const BIF_BROWSEINCLUDEFILES = &H4000
  2035. Const OFN_LONGNAMES = &H200000
  2036. Const OFN_NOLONGNAMES = &H40000
  2037. Const ssfDRIVES = &H11
  2038. Const ssfNETWORK = &H12
  2039. Set sa = CreateObject("Shell.Application")
  2040. var1=ArgObj(0)
  2041. Set sFld = sa.BrowseForFolder(0, var1, BIF_EDITBOX + BIF_VALIDATE + BIF_BROWSEINCLUDEFILES + BIF_RETURNFSANCESTORS+BIF_NEWDIALOGSTYLE , ssfDRIVES )
  2042. if not sFld is nothing Then
  2043.     if not left(sFld.items.item.path,1)=":" Then
  2044.         WScript.Echo sFld.items.item.path
  2045.     Else
  2046.         WScript.Echo "invalid"
  2047.     End If
  2048. Else
  2049.     WScript.Echo "cancel"
  2050. End If
  2051. ';
  2052.     if( !$wshSaved){
  2053.         $cscript = $ptmp.DIRECTORY_SEPARATOR."bf.vbs";
  2054.         $fh = fopen($cscript,"wb+");
  2055.         fwrite($fh,$wsh_browserfolder,strlen($wsh_browserfolder));
  2056.         fclose($fh);
  2057.         $wshSaved  = true;
  2058.     }
  2059.     exec('cscript '.$cscript.' "'.$label.'" //noLogo',$arPath);
  2060.     if($arPath[0]=='' || $arPath[0]=='cancel'){
  2061.         return '';
  2062.     } elseif ($arPath[0]=='invalid') {
  2063.         echo "Invalid Path.\n";
  2064.         return '';
  2065.     }
  2066.     return $arPath[0];
  2067. }
  2068.  
  2069. // }}}
  2070. // {{{ win32CreateRegEnv
  2071.  
  2072. /*
  2073.  * Generates a registry addOn for Win32 platform
  2074.  * This addon set PEAR environment variables
  2075.  * @Author Pierrre-Alain Joye
  2076.  */
  2077. function win32CreateRegEnv(){
  2078.     global $prefix, $bin_dir, $php_dir, $php_bin, $doc_dir, $data_dir, $test_dir;
  2079.     $nl = "\r\n";
  2080.     $reg ='REGEDIT4'.$nl.
  2081.             '[HKEY_CURRENT_USER\Environment]'.$nl.
  2082.             '"PHP_PEAR_SYSCONF_DIR"="'.addslashes($prefix).'"'.$nl.
  2083.             '"PHP_PEAR_INSTALL_DIR"="'.addslashes($php_dir).'"'.$nl.
  2084.             '"PHP_PEAR_DOC_DIR"="'.addslashes($doc_dir).'"'.$nl.
  2085.             '"PHP_PEAR_BIN_DIR"="'.addslashes($bin_dir).'"'.$nl.
  2086.             '"PHP_PEAR_DATA_DIR"="'.addslashes($data_dir).'"'.$nl.
  2087.             '"PHP_PEAR_PHP_BIN"="'.addslashes($php_bin).'"'.$nl.
  2088.             '"PHP_PEAR_TEST_DIR"="'.addslashes($test_dir).'"'.$nl;
  2089.     //$path = dirname(__FILE__).DIRECTORY_SEPARATOR;
  2090.     $fh = fopen($prefix.DIRECTORY_SEPARATOR.'PEAR_ENV.reg','wb');
  2091.     if($fh){
  2092.         fwrite($fh, $reg ,strlen($reg));
  2093.         fclose($fh);
  2094.         echo "
  2095.  
  2096. * WINDOWS ENVIRONMENT VARIABLES *
  2097. For convenience, a REG file is available under $prefix\\PEAR_ENV.reg .
  2098. This file creates ENV variables for the current user.
  2099.  
  2100. Double-click this file to add it to the current user registry.
  2101.  
  2102. ";
  2103.     }
  2104. }
  2105.  
  2106. // }}}
  2107. // {{{ win32DetectPHPSAPI
  2108.  
  2109. /*
  2110.  * Try to detect the kind of SAPI used by the
  2111.  * the given php.exe.
  2112.  * @Author Pierrre-Alain Joye
  2113.  */
  2114. function win32DetectPHPSAPI()
  2115. {
  2116.     global $php_bin;
  2117.     if($php_bin!=''){
  2118.         exec($php_bin.' -v', $res);
  2119.         if(is_array($res)) {
  2120.             if( isset($res[0]) && strpos($res[0],"(cli)")) {
  2121.                 return 'cli';
  2122.             }
  2123.             if( isset($res[0]) && strpos($res[0],"cgi")) {
  2124.                 return 'cgi';
  2125.             } else {
  2126.                 return 'unknown';
  2127.             }
  2128.         }
  2129.     }
  2130. }
  2131.  
  2132. // }}}
  2133. // {{{ getPhpiniPath
  2134.  
  2135. /*
  2136.  * Get the php.ini file used with the current
  2137.  * process or with the given php.exe
  2138.  *
  2139.  * Horrible hack, but well ;)
  2140.  *
  2141.  * Not used yet, will add the support later
  2142.  * @Author Pierre-Alain Joye <paj@pearfr.org>
  2143.  */
  2144. function getPhpiniPath()
  2145. {
  2146.     $pathIni = get_cfg_var('cfg_file_path');
  2147.     if( $pathIni && is_file($pathIni) ){
  2148.         return $pathIni;
  2149.     }
  2150.  
  2151.     // Oh well, we can keep this too :)
  2152.     // I dunno if get_cfg_var() is safe on every OS
  2153.     if (WINDOWS) {
  2154.         // on Windows, we can be pretty sure that there is a php.ini
  2155.         // file somewhere
  2156.         do {
  2157.             $php_ini = PHP_CONFIG_FILE_PATH . DIRECTORY_SEPARATOR . 'php.ini';
  2158.             if ( @file_exists($php_ini) ) break;
  2159.             $php_ini = 'c:\winnt\php.ini';
  2160.             if ( @file_exists($php_ini) ) break;
  2161.             $php_ini = 'c:\windows\php.ini';
  2162.         } while (false);
  2163.     } else {
  2164.         $php_ini = PHP_CONFIG_FILE_PATH . DIRECTORY_SEPARATOR . 'php.ini';
  2165.     }
  2166.  
  2167.     if( @is_file($php_ini) ){
  2168.         return $php_ini;
  2169.     }
  2170.  
  2171.     // We re running in hackz&troubles :)
  2172.     ob_implicit_flush(false);
  2173.     ob_start();
  2174.     phpinfo(INFO_GENERAL);
  2175.     $strInfo = ob_get_contents ();
  2176.     ob_end_clean();
  2177.     ob_implicit_flush(true);
  2178.  
  2179.     if ( php_sapi_name() != 'cli' ) {
  2180.         $strInfo = strip_tags($strInfo,'<td>');
  2181.         $arrayInfo  = explode("</td>", $strInfo );
  2182.         $cli = false;
  2183.     } else {
  2184.         $arrayInfo = explode("\n",$strInfo);
  2185.         $cli = true;
  2186.     }
  2187.  
  2188.     foreach($arrayInfo as $val){
  2189.         if ( strpos($val,"php.ini") ) {
  2190.             if($cli){
  2191.                 list(,$pathIni) = explode('=>',$val);
  2192.             } else {
  2193.                 $pathIni = strip_tags(trim($val) );
  2194.             }
  2195.             $pathIni = trim($pathIni);
  2196.             if(is_file($pathIni)){
  2197.                 return $pathIni;
  2198.             }
  2199.         }
  2200.     }
  2201.  
  2202.     return false;
  2203. }
  2204.  
  2205. // }}}
  2206. // {{{ alterPhpIni
  2207.  
  2208. /*
  2209.  * Not optimized, but seems to work, if some nice
  2210.  * peardev will test it? :)
  2211.  *
  2212.  * @Author Pierre-Alain Joye <paj@pearfr.org>
  2213.  */
  2214. function alterPhpIni($pathIni='')
  2215. {
  2216.     global $php_dir, $prefix;
  2217.  
  2218.     $iniSep = WINDOWS?';':':';
  2219.  
  2220.     if( $pathIni=='' ){
  2221.         $pathIni =  getphpinipath();
  2222.     }
  2223.  
  2224.     $arrayIni = file($pathIni);
  2225.     $i=0;
  2226.     $found=0;
  2227.  
  2228.     // Looks for each active include_path directives
  2229.     foreach ( $arrayIni as $iniLine ) {
  2230.         $iniLine = trim($iniLine);
  2231.         $iniLine = str_replace(array("\n","\r"),array(),$iniLine);
  2232.         if( preg_match("/^include_path/",$iniLine) ){
  2233.             $foundAt[] = $i;
  2234.             $found++;
  2235.         }
  2236.         $i++;
  2237.     }
  2238.  
  2239.     if ( $found ) {
  2240.         $includeLine = $arrayIni[$foundAt[0]];
  2241.         list(,$currentPath)=explode('=',$includeLine);
  2242.  
  2243.         $currentPath = trim($currentPath);
  2244.         if(substr($currentPath,0,1)=='"'){
  2245.             $currentPath = substr($currentPath,1,strlen($currentPath)-2);
  2246.         }
  2247.  
  2248.         $arrayPath = explode($iniSep, $currentPath);
  2249.         if( $arrayPath[0]=='.' ){
  2250.             $newPath[0] = '.';
  2251.             $newPath[1] = $php_dir;
  2252.             array_shift($arrayPath);
  2253.         } else {
  2254.             $newPath[0] = $php_dir;
  2255.         }
  2256.  
  2257.         foreach( $arrayPath as $path ){
  2258.             $newPath[]= $path;
  2259.         }
  2260.     } else {
  2261.         $newPath[0] = '.';
  2262.         $newPath[1] = $php_dir;
  2263.  
  2264.     }
  2265.     $nl = WINDOWS?"\r\n":"\n";
  2266.     $includepath = 'include_path="'.implode($iniSep,$newPath).'"';
  2267.     $newInclude =   "$nl$nl;***** Added by go-pear$nl".
  2268.                     $includepath.
  2269.                     $nl.";*****".
  2270.                     $nl.$nl;
  2271.  
  2272.     $arrayIni[$foundAt[0]] =  $newInclude;
  2273.  
  2274.     for( $i=1; $i<$found; $i++){
  2275.         $arrayIni[$foundAt[$i]]=';'.trim($arrayIni[$foundAt[$i]]);
  2276.     }
  2277.  
  2278.     $newIni = implode("",$arrayIni);
  2279.     if ( !($fh = @fopen($pathIni, "wb+")) ){
  2280.         $prefixIni = $prefix.DIRECTORY_SEPARATOR."php.ini-gopear";
  2281.         $fh = fopen($prefixIni, "wb+");
  2282.         if ( !$fh ) {
  2283.             echo
  2284. "
  2285. ******************************************************************************
  2286. WARNING!  I cannot write to $pathIni nor in $prefix/php.ini-gopear. Please
  2287. modify manually your php.ini by adding:
  2288.  
  2289. $includepath
  2290.  
  2291. ";
  2292.             return false;
  2293.         } else {
  2294.             fwrite($fh, $newIni, strlen($newIni));
  2295.             fclose($fh);
  2296.             echo
  2297. "
  2298. ******************************************************************************
  2299. WARNING!  I cannot write to $pathIni, but I succesfully created a php.ini
  2300. under <$prefix/php.ini-gopear>. Please replace the file <$pathIni> with
  2301. <$prefixIni> or modify your php.ini by adding:
  2302.  
  2303. $includepath
  2304.  
  2305. ";
  2306.  
  2307.         }
  2308.     } else {
  2309.         fwrite($fh, $newIni, strlen($newIni));
  2310.         fclose($fh);
  2311.         echo "
  2312. php.ini <$pathIni> include_path updated.
  2313. ";
  2314.     }
  2315.     return true;
  2316. }
  2317. ?>
  2318.